
/**
 * 按照要求搭建 HTTP 服务
 * 
 * GET   /login  显示表单网页
 * POST  /login  获取表单中的『用户名』和『密码』
 */

const fs = require("fs");
const path = require("path");
const express = require('express')
let bodyParser = require('body-parser')
const logger = require("./_unit/logs")
const app = express()

// create application/json parser
let jsonParser = bodyParser.json()
// create application/x-www-form-urlencoded parser
let urlencodedParser = bodyParser.urlencoded({ extended: false })

const filePath = path.resolve(__dirname, './test/07_获取请求体数据.html')

app.get("/login", (req, res) => {
    res.sendFile(filePath)
})

app.post("/login", urlencodedParser, (req, res) => {
    res.send(`<h3>用户名:${req.body.username}; 密码:${req.body.password}</h3>`)
})

app.listen(3000, () => {
    console.log("监听3000端口!");
})
